/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

export let a = new Array(1, 2, 3, 4, 5);

export let b = [1, 2, 3, 4, 5];

export let myMap1 = new Map([
  ['key1', 'value1'],
  ['1', '100'],
  ['true', 'booleanValue']
]);

export let myMap2 = new Map();

export let mySet1 = new Set([1, 2, 3, 2]);

export let mySet2 = new Set([1, 2, 3, 4, 5]);

export let myArrayBuffer1 = new ArrayBuffer(128);

export let myArrayBuffer2 = new ArrayBuffer(128);

export let myArrayBuffer3 = new ArrayBuffer(128);

export let buf = new ArrayBuffer(128);

export let view = new DataView(buf);

export let d = new Date(2025, 0, 1, 0, 0, 0);

export let weakMap = new WeakMap();

export let key = { name: "example" };
weakMap.set(key, "value associated with key");

export let weakSet = new WeakSet();

export let obj1 = {};

export const registry = new FinalizationRegistry(heldValue => {
  console.log('The object has been garbage collected: ${heldValue}');
});

export function foo(arg) {
  return JSON.parse(arg);
}

export function foo2(arg) {
  try {
    return JSON.parse(arg);
  } catch (error) {
    return error;
  }
}

export function foo3(arg, reviver) {
  return JSON.parse(arg, reviver);
}

export const jsonString = '{ "name": "John", "age": 30, "isMember": true, "deleted": "This is deleted" }';

export const reviver = (key, value) => {
  if (key === "deleted") {
    return undefined;
  }
  return value;
};

export function foo1(arg) {
  return JSON.stringify(arg);
}

export const num = 123;

export const str = '123';

export const obj = { name: "Alice", age: 25 };

export const arr = [1, "text", true];

export const obj_undef = { name: "Alice", age: undefined };

export const obj_func = {
  name: "Alice",
  greet() {
    return `Hello, ${this.name}!`;
  }
};

export function foo4(arg, replacer) {
  return JSON.stringify(arg, replacer);
}

export const replacer = (key, value) => {
  if (typeof value === "number") {
    return value * 2;
  }
  return value;
};

export const obj_replacer = { name: "John", age: 30 };